package com.bawei.network

import okhttp3.MultipartBody
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.FieldMap
import retrofit2.http.FormUrlEncoded
import retrofit2.http.GET
import retrofit2.http.HTTP
import retrofit2.http.Headers
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Part
import retrofit2.http.PartMap
import retrofit2.http.QueryMap
import retrofit2.http.Streaming
import retrofit2.http.Url

/**
 * Author: Jason Zhang
 * Date: 2024/4/25
 * Desc: API接口统一封装
 */
interface ApiService {

    /**
     * 使用Form表单发送POST请求
     */
    @POST
    @FormUrlEncoded
    suspend fun post(@Url url: String, @FieldMap map: Map<String, String>): ResponseBody

    /**
     * 使用Body发送POST请求
     */
    @POST
    suspend fun post(@Url url: String, @Body obj: Any): ResponseBody

    /**
     * JSON格式body参数的POST请求
     */
    @POST
    @Headers("Content-Type: application/json", "Accept: application/json")
    suspend fun postJson(@Url url:String, @Body jsonBody: RequestBody): ResponseBody

    /**
     * 发送普通的Body的POST请求
     */
    @POST
    suspend fun postBody(@Url url:String, @Body jsonBody: RequestBody): ResponseBody

    /**
     * 发送GET请求， 不带参数
     */
    @GET
    suspend fun get(@Url url:String): ResponseBody

    /**
     * 发送GET请求
     */
    @GET
    suspend fun get(@Url url:String, @QueryMap map: Map<String, String>): ResponseBody

    /**
     * 发送GET请求, 将URL进行编码，防止特殊字符和中文
     */
    @GET
    @FormUrlEncoded
    suspend fun getEncode(@Url url:String, @QueryMap map: Map<String, String>): ResponseBody

    /**
     * 发送删除请求
     */
    @DELETE
    suspend fun delete(@Url url:String, @QueryMap map: Map<String, String>): ResponseBody

    /**
     * 发送一个Http请求
     */
    @HTTP(method = "DELETE", hasBody = true)
    suspend fun deleteBody(@Url url: String, @Body obj: Any): ResponseBody


    @HTTP(method = "DELETE", hasBody = true)
    @Headers("Content-Type: application/json", "Accept: application/json")
    suspend fun deleteJson(@Url url: String, @Body jsonBody: RequestBody): ResponseBody

    @PUT
    suspend fun put(@Url url: String, @QueryMap maps: Map<String, String>): ResponseBody

    @PUT
    suspend fun putBody(@Url url: String, @Body obj: Any): ResponseBody

    @PUT
    suspend fun putBody(@Url url: String, @Body body: RequestBody?): ResponseBody

    @PUT
    @Headers("Content-Type: application/json", "Accept: application/json")
    suspend fun putJson(@Url url: String, @Body jsonBody: RequestBody): ResponseBody

    /**
     * 单个文件上传
     */
    @POST
    @Multipart
    suspend fun uploadFile(@Url fileUrl: String, @Part("description") description: RequestBody, @Part("files") file: MultipartBody.Part): ResponseBody

    /**
     * 多个文件上传
     */
    @POST
    @Multipart
    suspend fun uploadFiles(@Url url: String, @PartMap maps: Map<String, RequestBody>): ResponseBody

    /**
     * 多个文件上传
     */
    @POST
    @Multipart
    suspend fun uploadFiles( @Url url: String, @Part parts: List<MultipartBody.Part>): ResponseBody

    /**
     * 单个下载文件
     */
    @GET
    @Streaming
    suspend fun downloadFile(@Url fileUrl: String): ResponseBody

}